
package ch.hearc.coursJava.examen.controle;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.Box;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;

/**
 *
 * @author raphael.capocasa
 *
 */
public class JPanelCentre extends JPanel
	{
	/**
     * 
     */
    private static final long serialVersionUID = 2377209973443936529L;
    /*------------------------------------------------------------------*\
	|*							Constructeurs							*|
	\*------------------------------------------------------------------*/
	public JPanelCentre(JFrame frame)
		{
		this.frame = frame;
		creerComposant();
		placerComposant();
		addListener();
		}

	/*------------------------------------------------------------------*\
	|*							Methodes Private						*|
	\*------------------------------------------------------------------*/
	private void placerComposant()
		{
		this.boxLayout = Box.createHorizontalBox();
		add(boxLayout);
		boxLayout.add(btnStart);
		boxLayout.add(btnStop);
		}

	private void creerComposant()
		{
		btnStart = new JButton("Start");
		btnStop = new JButton("Stop");
		}

	private void addListener()
		{
		this.btnStart.addActionListener(new ActionListener()
			{
				@SuppressWarnings("deprecation")
				@Override
				public void actionPerformed(ActionEvent arg0)
					{
					JFrameControle f = (JFrameControle)frame;
					Thread t = f.getThread();
					t.stop();
					}
			});

		this.btnStop.addActionListener(new ActionListener()
			{
				@SuppressWarnings("deprecation")
				@Override
				public void actionPerformed(ActionEvent arg0)
					{
					JFrameControle f = (JFrameControle)frame;
					Thread t = f.getThread();
					t.resume();
					}
			});
		}

	/*------------------------------------------------------------------*\
	|*							Attributs Private						*|
	\*------------------------------------------------------------------*/
	//input
	private JFrame frame;

	//tools
	private JButton btnStart;
	private JButton btnStop;
	private Box boxLayout;
	}

